<?php 
include_once __DIR__.'/vendor/autoload.php';  
if (strpos(strtolower(PHP_OS), 'win') === 0) {
    class_alias(\Windows\Events\Select::class, \Workerman\Events\Select::class);
    class_alias(\Windows\Worker::class, \Workerman\Worker::class);
}  

// class Client extends Channel\Client{
//     public static $_events=array();
// }

$c = new Channel\Server('0.0.0.0', 22060);
$w = new \Workerman\Worker('tcp://0.0.0.0:8881'); 
$w->count=4;
$w->onWorkerStart = function($w){ 
 
    Channel\Client::connect('127.0.0.1', 22060);

    $arr=['ev1','ev2','ev3'];
    for ($i=0; $i < 100; $i++) {  
        $ev = $arr[ array_rand($arr)]; 
        $name = $w->id.':'.$ev."\n";
        Channel\Client::on($ev, function()use($name) { echo $name;  }); 
    }
     
    sleep($w->id+1);
    print_r(Channel\Client::$_events);

    if($w->id==0){
        sleep(4);
        echo "\n";
        echo "\n";
        Channel\Client::publish('ev1','');
        sleep(1);
        echo "\n";
        echo "\n";
        Channel\Client::publish('ev2','');
        sleep(1);
        echo "\n";
        echo "\n";
        Channel\Client::publish('ev3',''); 
    }

};  
 
\Workerman\Worker::runAll();